"""
selenium抓取猫眼电影top100
"""

from selenium import webdriver

# 1.打开浏览器,进入主页
driver = webdriver.Chrome()
driver.get(url='https://maoyan.com/board/4')

# 2.提取数据
def get_one_page():
    dd_list = driver.find_elements_by_xpath('//dl/dd')
    for dd in dd_list:
        item = {}
        item['rank'] = dd.find_element_by_xpath('./i[1]').text
        item['title'] = dd.find_element_by_xpath('.//p[@class="name"]/a').get_attribute('title')
        item['star'] = dd.find_element_by_class_name("star").text
        item['time'] = dd.find_element_by_class_name("releasetime").text
        item['score'] = dd.find_element_by_class_name("score").text
        print(item)

while True:
    get_one_page()
    try:
        driver.find_element_by_link_text('下一页').click()
    except Exception as e:
        driver.quit()
        break






























